package edu.zqu.instructionalMatters.project.util;

import edu.zqu.instructionalMatters.project.VO.TeacherIntentionVO;
import edu.zqu.instructionalMatters.project.entity.Semester;
import edu.zqu.instructionalMatters.project.entity.TeacherIntention;
import edu.zqu.instructionalMatters.project.mapper.SemesterMapper;
import edu.zqu.instructionalMatters.project.service.CollegeService;
import edu.zqu.instructionalMatters.project.service.CourseService;
import edu.zqu.instructionalMatters.project.service.InstructionClassService;
import edu.zqu.instructionalMatters.project.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author 何文东
 * @Date 2020/7/25 16:32
 * @Description:
 * @Version 1.0
 */
@Component
public class TeacherIntentionUtil {
    @Autowired
    private CollegeService collegeService;
    @Autowired
    private SemesterMapper semesterMapper;
    @Autowired
    private CourseService courseService;
    @Autowired
    private InstructionClassService instructionClassService;
    @Autowired
    private UserService userService;

    public TeacherIntentionVO teacherIntentionUtil(TeacherIntention teacherIntention) {
        TeacherIntentionVO teacherIntentionVO = new TeacherIntentionVO();                              //初始化VO
        BeanUtils.copyProperties(teacherIntention, teacherIntentionVO);                                 //对象复制赋值

        String collegeName = collegeService.getCollegeName(teacherIntention.getCollegeId());           //获取学校名称
        teacherIntentionVO.setCollegeName(collegeName);                                                //设置学校名称

        Semester semester = semesterMapper.selectById(teacherIntention.getSemesterId());               //获取学期对象
        teacherIntentionVO.setSemesterName(null);                                                      //设置学期名称null
        if (semester != null) {
            teacherIntentionVO.setSemesterName(semester.getName());                                    //设置学期名称
        }

        String courseName = courseService.getCourseName(teacherIntention.getCourseId());               //获取课程名称
        teacherIntentionVO.setCourseName(courseName);                                                  //设置课程名称

        String instructionClassName = instructionClassService.getInstructionClassName(teacherIntention.getInstructionClassId());//授课班级名称
        teacherIntentionVO.setInstructionClassName(instructionClassName);                              //设置授课班级名称

        String teacherName = userService.getUserName(teacherIntention.getTeacherId());                 //获取教师名称
        teacherIntentionVO.setTeacherName(teacherName);                                                //设置教师名称

        return teacherIntentionVO;
    }
}
